package com.wjj.dao.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wjj.dao.constants.CollectionConstants;
import com.wjj.dao.po.StudentPO;
import com.wjj.dao.repository.mapper.StudentCrudMapper;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * @Description
 * @Author junjun Wang
 * @Date Create in 0:11 2023/12/7
 **/
@Repository
public class StudentRepositoryImpl extends ServiceImpl<StudentCrudMapper, StudentPO> implements
		StudentRepository {

	@Autowired
	private StudentCrudMapper studentCrudMapper;

	@Override
	public List<StudentPO> getStudents() {
		return studentCrudMapper.selectList(new QueryWrapper<>());
	}

	@Override
	public StudentPO getStudentById(Integer studentId) {
		return studentCrudMapper.selectById(studentId);
	}

	@Override
	public Boolean addStudent(List<StudentPO> students) {
		return this.saveBatch(students);
	}

	@Override
	public Integer updateStudent(StudentPO student) {
		return studentCrudMapper.updateById(student);
	}

	@Override
	public Integer deleteStudentById(Integer studentId) {
		return studentCrudMapper.deleteById(studentId);
	}

	@Override
	public List<StudentPO> getStudentByClassId(Integer classId) {
		QueryWrapper<StudentPO> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(CollectionConstants.CLASS_ID, classId);
		return studentCrudMapper.selectList(queryWrapper);
	}
}
